package com.example.manager.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.manager.domain.R;
import com.example.manager.domain.SysPost;
import com.example.manager.domain.UserLoginLog;
import com.example.manager.service.UserLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/slm/login")
@RestController
public class LogController {
    @Autowired
    UserLoginLogService userLoginLogService;


    @GetMapping("/find")
    public R<Page> find(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "2") Integer size,
            @RequestParam String userName,
            @RequestParam String ipAddr,
            @RequestParam String status,
            @RequestParam String loginTime

            ) {

        //创建分页对象
        Page<UserLoginLog> page = new Page<>(current,size);
        QueryWrapper<UserLoginLog> queryWrapper = new QueryWrapper<>();
        if (ipAddr!=null){
            queryWrapper.lambda().like(UserLoginLog::getIpAddr,ipAddr);
        }
        if (userName!=null){
            queryWrapper.lambda().like(UserLoginLog::getUserName,userName);
        }
        if (status!=null && !status.equals("")){
            queryWrapper.lambda().eq(UserLoginLog::getStatus,status);
        }
        if (loginTime!=null){
            queryWrapper.lambda().eq(UserLoginLog::getLoginTime,loginTime);
        }
        //根据分页对象，查询分页数据
        page = userLoginLogService.page(page,queryWrapper);
        return R.success(page);
    }
}
